﻿@model Fish.Models.Events


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Events</h4>
        <hr />
        @Html.ValidationSummary(true)

        <div class="form-group">
            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.PrivacyType, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.RadioButtonFor(model => model.PrivacyType, 0)
                @Html.LabelFor(model => model.PrivacyType, "Private")
                @Html.RadioButtonFor(model => model.PrivacyType, 1)
                @Html.LabelFor(model => model.PrivacyType, "Public")
                @Html.ValidationMessageFor(model => model.PrivacyType)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TemplatesID, "Templates", new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("TemplatesID", "Pick a template")
                @Html.ValidationMessageFor(model => model.TemplatesID)
                <input id="createTemplate" type="image" src="~/Repository/Icons/plus.png" width="25" height="25" alt="Add">
                @Html.Label("Add New Template")
            </div>
            

            


        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to Events", "Index","EventUserRelations")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script src="~/Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {


            $("#createTemplate").click(function () {
                event.preventDefault();                var eventName = $("#Name").val();
              
                var eventPrivacy = $("input[id=PrivacyType]:checked").val();
              
                var postData = { eventName: eventName, eventPrivacy: eventPrivacy };

                $.ajax({
                    type: "POST",
                    url: "/Events/CreateTemplate",
                    data: postData,
                    success: function (data, textStatus, xhr) {
                        window.location.href = data.redirectToUrl;
                    },
                    error: function (data, textStatus, xhr) {
                            window.location.href = data.redirectToUrl;
                        },
                    dataType: "json",
                    traditional: true

                });
            });
        });



     
</script>